'use strict';

/**
 * Config for the router
 */
angular.module('app')
    .run(
        ['$rootScope', '$state', '$stateParams', '$cookieStore', 'apiService',
            function ($rootScope, $state, $stateParams, $cookieStore, apiService) {
                $rootScope.$state = $state;
                $rootScope.$stateParams = $stateParams;
                $rootScope.userObj = $cookieStore.get('cy__member');
                // 判断是否绑定充值账户
                if ($rootScope.userObj) {
                    apiService.post({
                        modelName: 'account',
                        apiName: 'getAccountByMem'
                    }, {
                        memberId: $rootScope.userObj['id']
                    }, function (data) {
                        if (data.code == 200) {
                            $rootScope.accountUserObj = data['data'];
                        } else {}
                    },function(err){
                        console.log(err);
                    });
                }
            }
        ]
    )
    .config(
        ['$stateProvider', '$urlRouterProvider',
            function ($stateProvider, $urlRouterProvider) {

                $urlRouterProvider
                    .otherwise('/app/dashboard-v1');
                $stateProvider
                    .state('app', {
                        abstract: true,
                        url: '/app',
                        templateUrl: 'tpl/app.html',
                        controller: function ($rootScope, $cookieStore, $state) {
                            if ($cookieStore.get('cy__member')) {
                                $rootScope.userObj = $cookieStore.get('cy__member');
                            } else {
                                $state.go('access.signin');
                            }
                        }
                    })
                    .state('app.dashboard-v1', {
                        url: '/dashboard-v1',
                        templateUrl: 'tpl/app_dashboard_v1.html'
                    })

                    // memeber
                    .state('app.member', {
                        url: '/member',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load('js/controllers/member.js');
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.member.add', {
                        url: '/add',
                        templateUrl: 'tpl/member_add.html'
                    })
                    .state('app.member.info', {
                        url: '/info',
                        templateUrl: 'tpl/member_info.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load('js/controllers/member_info.js');
                                }
                            ]
                        }
                    })
                    .state('app.member.upPass', {
                        url: '/upPass',
                        templateUrl: 'tpl/member_upPass.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load('js/controllers/member_upPass.js');
                                }
                            ]
                        }
                    })


                    //mood
                    .state('app.mood', {
                        url: '/mood',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load('js/controllers/mood.js');
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.mood.add', {
                        url: '/add',
                        templateUrl: 'tpl/mood_add.html'
                    })
                    .state('app.mood.list', {
                        url: '/list',
                        templateUrl: 'tpl/mood_list.html'
                    })

                    //nomemer
                    .state('app.nomember', {
                        url: '/nomember',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load('js/controllers/nomember.js');
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.nomember.list', {
                        url: '/list',
                        templateUrl: 'tpl/nomember_list.html'
                    })


                    // team
                    .state('app.team', {
                        url: '/team',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load('js/controllers/team.js');
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.team.list', {
                        url: '/list',
                        templateUrl: 'tpl/team_list.html'
                    })


                    // capital 
                    .state('app.capital', {
                        url: '/capital',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load('js/controllers/capital.js');
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.capital.list', {
                        url: '/list',
                        templateUrl: 'tpl/capital_list.html'
                    })
                    .state('app.capital.bind', {
                        url: '/bind',
                        templateUrl: 'tpl/capital_bind.html'
                    })
                    .state('app.capital.bindList', {
                        url: '/bindList',
                        templateUrl: 'tpl/capital_bindList.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/controllers/capital_bindList.js']);
                                }
                            ]
                        }
                    })


                    //fund
                    .state('app.fund', {
                        url: '/fund',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load('js/controllers/fund.js');
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.fund.recharge', {
                        url: '/recharge',
                        templateUrl: 'tpl/fund_recharge.html'
                    })
                    .state('app.fund.transfer', {
                        url: '/transfer',
                        templateUrl: 'tpl/fund_transfer.html'
                    })
                    .state('app.fund.deposit', {
                        url: '/deposit',
                        templateUrl: 'tpl/fund_deposit.html'
                    })


                    //access
                    .state('access', {
                        url: '/access',
                        template: '<div ui-view class="fade-in-right-big smooth"></div>'
                    })
                    .state('access.signin', {
                        url: '/signin',
                        templateUrl: 'tpl/page_signin.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/controllers/signin.js']);
                                }
                            ]
                        }
                    })



            }
        ]
    );